﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using 纸片人.CalculateControls;

//https://go.microsoft.com/fwlink/?LinkId=234236 上介绍了“用户控件”项模板

namespace 纸片人.win2dEffectControl.SliderFloder
{
    public sealed partial class RectSlider : UserControl
    {

        public object Header
        {
            get { return (object)GetValue(HeaderProperty); }
            set { SetValue(HeaderProperty, value); }
        }

        // Using a DependencyProperty as the backing store for Header.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty HeaderProperty =
            DependencyProperty.Register("Header", typeof(object), typeof(Vector2Control), new PropertyMetadata(null));



        public Rect Rect
        {
            get { return (Rect)GetValue(RectProperty); }
            set { SetValue(RectProperty, value); }
        }

        // Using a DependencyProperty as the backing store for Rect.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty RectProperty =
            DependencyProperty.Register("Rect", typeof(Rect), typeof(RectSlider), new PropertyMetadata(new Rect(),RectPropertyChanged));

        private static void RectPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var rpc = d as RectSlider; 
            if (rpc != null)
            {
                rpc.SetRect((Rect)e.NewValue);
            }
        }

        public delegate void RectChangeHeader(object sender, Rect value);
        public event RectChangeHeader RectChanging;
        public event RectChangeHeader RectChanged;

        public RectSlider()
        {
            this.InitializeComponent();
        }


        private void Slider_Changing(TextBoxSlider sender, double newValue)
        {
            Rect = GetRect();

            RectChanging?.Invoke(this, GetRect());
        }

        private void Slider_Changed(TextBoxSlider sender, double newValue, double oldValue)
        {
            Rect = GetRect();
            RectChanged?.Invoke(this, GetRect());

        }

        public void SetRect(Rect rect)
        {
            //xSlider.Value = rect.X;
            //ySlider.Value = rect.Y;
            //widthSlider.Value = rect.Width;
            //heightSlider.Value = rect.Height;
        }

        public void SetRect(Vector4 vector)
        {
            
            SetRect(new Rect(vector.X, vector.Y, vector.Z, vector.W));
        }

        public void SetRect(double x,double y,double width,double height)
        {
            SetRect(new Rect(x,y,width,height));
        }

        public Rect GetRect()
        {
            //var rect =new Rect(xSlider.Value,ySlider.Value,widthSlider.Value,heightSlider.Value);
            //return rect;

            return new Rect();
        }
    }
}
